//
//  LHCustomTitleView.m
//  LHImagePicker
//
//  Created by 刘辉 lewis on 2018/6/13.
//  Copyright © 2018年 刘辉 lewis. All rights reserved.
//

#import "LHCustomTitleView.h"

@interface LHCustomTitleView()
@property(nonatomic,weak)id<LHCustomTitleViewDelegate>delegate;
@property(nonatomic,strong)LHNavTitleChooseButton*titleBtn;
@end

@implementation LHCustomTitleView

-(instancetype)initWithFrame:(CGRect)frame andDelegate:(id)delegate{
    if (self=[super initWithFrame:frame]) {
        if (delegate) {
            self.delegate=delegate;
        }
        [self addSubview:self.titleBtn];
    }
    return self;
}
-(LHNavTitleChooseButton*)titleBtn{
    if (_titleBtn==nil) {
        _titleBtn=[LHNavTitleChooseButton buttonWithType:UIButtonTypeCustom];
        [_titleBtn setTitle:@"全部照片" forState:UIControlStateNormal];
        [_titleBtn setImage:[UIImage imageNamed:@"LHImagePicker.bundle/navigationbar_arrow_down"] forState:UIControlStateNormal];
        [_titleBtn addTarget:self action:@selector(titleBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _titleBtn;
}
-(void)titleBtnDidClick:(LHNavTitleChooseButton*)btn{
    [btn setImage:btn.selected?[UIImage imageNamed:@"LHImagePicker.bundle/navigationbar_arrow_down"]:[UIImage imageNamed:@"LHImagePicker.bundle/navigationbar_arrow_up"] forState:UIControlStateNormal];
    btn.selected=!btn.selected;
    if (self.delegate && [self.delegate respondsToSelector:@selector(lh_customNavTitleBtnDidiClick:andSelectedTitleBtnStatus:)]) {
        [self.delegate lh_customNavTitleBtnDidiClick:btn andSelectedTitleBtnStatus:btn.selected?TitleBtnStatusUp:TitleBtnStatusDown];
    }
}


@end
